/*
	This file is part of "Ants on the web".

    "Ants on the web" is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Ants on the web" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Ants on the web".  If not, see <http://www.gnu.org/licenses/>.
*/

package org.utc.ia04.antsontheweb.antColonyOptimisation.antColony;


import org.utc.ia04.antsontheweb.utilities.Requete;
import org.utc.ia04.antsontheweb.utilities.RequeteException;

import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

public class InformMsgReceptionBhv extends CyclicBehaviour 
{
	//serialVersionUID
	private static final long serialVersionUID = -1678812346308011241L;

	public void action()
	{
		MessageTemplate model = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
		ACLMessage msg = myAgent.receive(model);
		if(msg == null) block();
		else
		{
			try
			{
				Requete query = Requete.deserialize_withException(msg.getContent(), myAgent, msg);
				switch(query.getType())
				{
					case Requete.ANT_DYING:
						((AntColonyAgent)myAgent).decAntNumber();
						break;
					case Requete.ANT_RESSOURCEPICKUP:
						((AntColonyAgent)myAgent).incRessourceCollectedNb();
						break;
					default:
						System.out.println(myAgent.getName()+"received message:"+msg.getContent()+"and not know how to treat it.");
						break;	
				}
			}
			catch (RequeteException e) { }
		}
	}
	
}
